# Importing Data
RUSSIA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Magnesium/Magnesium.xlsx",sheet = "Sheet1", range = "F1:F264")

# Checking the Imported Data
View(RUSSIA)
# Creating Time Series Data
RUSSIA_ts <- ts(RUSSIA, start=c(1998,1), end=c(2018,12), frequency=12)
# Viewing and Checking the Created Time Series Data
RUSSIA_ts
sum(is.na(RUSSIA_ts))
library(forecast)
RUSSIA_ts <- tsclean(RUSSIA_ts)
RUSSIA_ts

# Identification: Plotting the Time Series Data
plot(RUSSIA_ts)

# Estimating the appropriate model
RUSSIA_ts_model <- auto.arima(RUSSIA_ts)
RUSSIA_ts_model

# Forecasting
options(max.print=1000000)
RUSSIA_ts_forecast <- forecast (RUSSIA_ts_model, level=c(95), h=264)
plot(RUSSIA_ts_forecast)
RUSSIA_ts_forecast             

# Exporting
write.table(RUSSIA_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Magnesium/RUSSIA_TSA.csv", sep=",")
